//
//  SavedStationCell.m
//  StationManager
//
//  Created by 张佳强 on 18/5/17.
//  Copyright © 2018年 Helong. All rights reserved.
//

#import "SavedStationCell.h"
#import <Masonry.h>
@implementation SavedStationCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}


-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        _selectButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_selectButton setImage:[UIImage imageNamed:@"unselected_bg"] forState:UIControlStateNormal];
        [_selectButton setImage:[UIImage imageNamed:@"selected_bg"] forState:UIControlStateSelected];
        [_selectButton addTarget:self action:@selector(selectClick) forControlEvents:UIControlEventTouchUpInside];
        _selectButton.selected = NO;
        [self.contentView addSubview:_selectButton];
        
        [_selectButton mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.left.equalTo(@5);
            make.top.bottom.equalTo(@0);
            make.width.mas_equalTo(30);
        }];
        
        _nameLabel = [[UILabel alloc] init];
        _nameLabel.font = [UIFont systemFontOfSize:13];
        [self.contentView addSubview:_nameLabel];
        
        [_nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.left.equalTo(_selectButton.mas_right).offset(5);
            make.top.bottom.equalTo(@0);
            make.right.equalTo(@-5);
        }];
    }
    return self;
}

-(void)selectClick{
    
    
    
    
    if (self.selectButton.selected) {
        self.selectButton.selected = NO;
        if ([_type isEqualToString:@"unupload"]) {
            [self.savedStationDelegate removeDocumentname:self.cellTag];

        }
        else{
            [self.uploadStationDelegate removeuploadDocumentname:self.cellTag];

        }
        
    }else{
        self.selectButton.selected = YES;
        
        if ([_type isEqualToString:@"unupload"]) {
            [self.savedStationDelegate sendDocumentName:self.cellTag];
            
        }
        else{
            [self.uploadStationDelegate senduploadDocumentName:self.cellTag];
            
        }
        
    }
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
